//
//  LGSportsCollectionCell.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/8/8.
//

#import "LGSportsCollectionCell.h"

@interface LGSportsCollectionCell()
/**   */
@property (nonatomic , strong)UIImageView *headPic;
/**   */
@property (nonatomic , strong)UILabel *nameLabel;
/**   */
@property (nonatomic , strong)UIButton *deleteBtn;

@end

@implementation LGSportsCollectionCell

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubView];
    }
    return self;
}

-(void)setDataDic:(NSDictionary *)dataDic{
    _dataDic = dataDic;
    UIImage *placeHolder = [dataDic[@"gender"] isEqualToString:@"女"]?defaultPatientWomen:defaultPatientMan;
    [self.headPic sd_setImageWithURL:[NSURL URLWithString:LGNSString(dataDic[@"avatar_url"])] placeholderImage:placeHolder];
    self.nameLabel.text = LGNSString(dataDic[@"realname"]);
}

//删除患者
-(void)deleteBtnAction{
    if(self.delegate && [self.delegate respondsToSelector:@selector(deletePatient:)]){
        [self.delegate deletePatient:LGNSString(self.dataDic[@"id"])];
    }
}


-(void)createSubView{
    [self.contentView addSubview:self.headPic];
    [self.contentView addSubview:self.nameLabel];
    [self.contentView addSubview:self.deleteBtn];
    [self.headPic mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(viewPix(8));
        make.centerX.equalTo(self.contentView);
        make.width.height.equalTo(@(viewPix(42)));
    }];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(viewPix(5));
        make.right.equalTo(self.contentView).offset(-viewPix(5));
        make.top.equalTo(self.contentView).offset(viewPix(54));
    }];
    [self.deleteBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.right.equalTo(self.contentView);
        make.width.height.equalTo(@(viewPix(24)));
    }];
}
-(UIImageView *)headPic{
    if(!_headPic){
        _headPic = [[UIImageView alloc]init];
        _headPic.cornerRidus = 5;
    }
    return _headPic;
}

-(UILabel *)nameLabel{
    if(!_nameLabel){
        _nameLabel = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFont(14) textAlignment:NSTextAlignmentCenter lines:1];
    }
    return _nameLabel;
}

-(UIButton *)deleteBtn{
    if(!_deleteBtn){
        _deleteBtn = [UIButton buttonWithImage:@"运动方案-删除患者" selectImage:@"运动方案-删除患者"];
        [_deleteBtn addTarget:self action:@selector(deleteBtnAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _deleteBtn;
}

@end
